<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It is a breeze. Simply tell Lumen the URIs it should respond to
| and give it the Closure to call when that URI is requested.
|
*/

$api = app('Dingo\Api\Routing\Router');
$api->version(['v1'], function ($api) {
    /* @var $api Dingo\Api\Routing\Router */
    $api->group(
        [
            'namespace' => 'App\Http\Controllers\Api\v1',
            'middleware' => 'api.throttle',
            'limit' => 200, 'expires' => 1
        ],
        function ($api) {
            /* @var $api Dingo\Api\Routing\Router */

            // 授权
            $api->post('auth/login', 'AuthController@login');
            $api->post('auth/logout', 'AuthController@logout');
            $api->get('auth/user', 'AuthController@user');

            // 公共方法
            $api->post('image-upload', 'CommonController@imageUpload');

            // 资源
            $resource = ['menu', 'node', 'tag', 'link', 'article', 'single_page', 'archive'];
            foreach ($resource as $value) {
                $content = str_plural($value);
                $controller = studly_case($value) . 'Controller';
                $api->get($content, "{$controller}@index");
                $api->post($content, "{$controller}@store");
                $api->get("{$content}/{id}", "{$controller}@show");
                $api->put("{$content}/{id}", "{$controller}@update");
                $api->delete("{$content}/{id}", "{$controller}@destroy");
            }

            $api->get('site_config', 'SiteConfigController@index');
            $api->put('site_config', 'SiteConfigController@update');
        }
    );
});

